/**
 * @file engineer_mode_telephony.c
 *
 */

/*********************
 *      INCLUDES
 *********************/
#include "lv_watch.h"

#if USE_LV_WATCH_ENGINEER_MODE!= 0

/*********************
 *      DEFINES
 *********************/
#define ENGINEER_MODE_TELEPHONY_LIST_CNT    7
#define TELEPHONY_LTE_CELL_INFO_LIST_CNT    3
#define TELEPHONY_GSM_CELL_INFO_LIST_CNT    3
#define ENGINEER_MODE_DEF_GSM_BAND  0x7F
#define ENGINEER_MODE_DEF_LTE_BAND  0x1FFF
#define ENGINEER_MODE_GSM_MODE 0
#define ENGINEER_MODE_LTE_MODE 5
#define ENGINEER_MODE_DUAL_MODE_GSM_LTE_AUTO 6

/**********************
 *      TYPEDEFS
 **********************/

/**********************
 *  STATIC PROTOTYPES
 **********************/
static void telephony_btn_rel_event_cb(lv_obj_t * btn, lv_event_t e);
static void auto_answer_create(lv_obj_t * par);
static void band_mode_create(lv_obj_t * par);
static void lte_info_create(lv_obj_t * par);
static void gsm_info_create(lv_obj_t * par);
static void gps_create(lv_obj_t * par);
static void sn_info_create(lv_obj_t * par);
static void calibration_query_create(lv_obj_t * par);
static void telephony_prepare_destory(lv_obj_t * activity_obj);
static lv_obj_t * band_mode_list_add(lv_obj_t * list, char * str, bool cb_need, lv_event_cb_t event);
static void band_mode_option_btn_create(lv_obj_t * par);
static void update_sel_band(lv_obj_t * btn, uint32_t index);
static lv_band_mode_obj_ext_t * band_mode_get_ext(void);
static void band_mode_ext_init(void);
static void band_btn_rel_event_cb(lv_obj_t * btn, lv_event_t e);
static void set_result_create(lv_obj_t * par);
static void reset_result_create(lv_obj_t * par);
static void set_btn_event_cb(lv_obj_t * btn, lv_event_t e);
static void reset_default_btn_event_cb(lv_obj_t * btn, lv_event_t e);
static void update_sel_gsm_band(uint8_t gsm_bitmap);
static void update_sel_lte_band(uint16_t lte_bitmap);
static uint8_t update_gsm_band_bitmap(void);
static uint16_t update_lte_band_bitmap(void);
static void config_modem_sel_band(void);
static void lte_scell_btn_rel_action(lv_obj_t * par);
static void lte_ncell_btn_rel_action(lv_obj_t * par);
static void lte_irat_ncell_btn_rel_action(lv_obj_t * par);
static void gsm_scell_btn_rel_action(lv_obj_t * par);
static void gsm_ncell_btn_rel_action(lv_obj_t * par);
static void gsm_irat_ncell_btn_rel_action(lv_obj_t * par);

/**********************
 *  STATIC VARIABLES
 **********************/
const lv_engineer_item_t engineer_mode_telephony_list[] = {
    { WATCH_TEXT_ID_EMODE_TEL_AUTO_ANSWER, auto_answer_create, NULL },
    { WATCH_TEXT_ID_EMODE_TEL_BAND_MODE, band_mode_create, NULL },
    { WATCH_TEXT_ID_EMODE_TEL_LTE_INFO, lte_info_create, NULL },
    { WATCH_TEXT_ID_EMODE_TEL_GSM_INFO, gsm_info_create, NULL },
    { WATCH_TEXT_ID_EMODE_TEL_GPS, gps_create, NULL },
    { WATCH_TEXT_ID_EMODE_TEL_SN_INFO, sn_info_create, NULL },
    { WATCH_TEXT_ID_EMODE_TEL_CALIBRATION_QUERY, calibration_query_create, NULL },
};

const lv_engineer_item_t telephony_cell_info_list[] = {
    { WATCH_TEXT_ID_EMODE_TEL_LTE_SCELL, lte_scell_btn_rel_action, cell_info_prepare_destory },
    { WATCH_TEXT_ID_EMODE_TEL_LTE_NCELL, lte_ncell_btn_rel_action, cell_info_prepare_destory },
    { WATCH_TEXT_ID_EMODE_TEL_LTE_IRAT_NCELL, lte_irat_ncell_btn_rel_action, cell_info_prepare_destory },
    { WATCH_TEXT_ID_EMODE_TEL_GSM_SCELL, gsm_scell_btn_rel_action, cell_info_prepare_destory },
    { WATCH_TEXT_ID_EMODE_TEL_GSM_NCELL, gsm_ncell_btn_rel_action, cell_info_prepare_destory },
    { WATCH_TEXT_ID_EMODE_TEL_GSM_IRAT_NCELL, gsm_irat_ncell_btn_rel_action, cell_info_prepare_destory },
};

/**********************
 *      MACROS
 **********************/

/**********************
 *   GLOBAL FUNCTIONS
***********************/
lv_obj_t * engineer_mode_telephony_create(lv_obj_t * activity_obj)
{
    lv_obj_t * obj;
    if(activity_obj == NULL) {
        lv_watch_activity_ext_t activity_ext;
        memset(&activity_ext, 0, sizeof(lv_watch_activity_ext_t));
        activity_ext.actId = ACT_ID_ENGINEER_MODE_TELEPHONY;
        activity_ext.create = engineer_mode_telephony_create;
        activity_ext.prepare_destory = telephony_prepare_destory;
        activity_obj = lv_watch_creat_activity_obj(&activity_ext);
        LV_ASSERT_MEM(activity_obj);
        if(NULL == activity_obj) {
            return NULL;
        }
    }

    obj = lv_watch_obj_create(activity_obj);
    LV_ASSERT_MEM(obj);
    if(NULL == obj) {
        return NULL;
    }

    lv_obj_t * title = lv_label_create(obj, NULL);
    lv_obj_set_size(title, LV_HOR_RES, LV_VER_RES / 4);
    lv_label_set_text_id(title, WATCH_TEXT_ID_ENGINEER_MODE_TELEPHONY);
    lv_obj_add_style(title, LV_LABEL_PART_MAIN, &lv_watch_font30);
    lv_obj_align(title, NULL, LV_ALIGN_IN_TOP_MID, 0, 5);

    lv_obj_t * list = lv_list_create(obj, NULL);
    lv_obj_set_size(list, LV_HOR_RES, LV_VER_RES - lv_obj_get_height(title) - 20);
    lv_page_set_edge_flash(list, true);
    lv_obj_add_style(list, LV_LIST_PART_EDGE_FLASH, &lv_watch_cont_opa1);
    lv_obj_align(list, title, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);

    lv_engineer_main_obj_ext_t * ext = engineer_mode_get_ext();
    lv_obj_add_style(list, LV_LIST_PART_BG,  &lv_watch_style_transp);

    uint8_t i = 0;
    lv_obj_t * btn;
    lv_obj_t * label;
    for(i = 0; i < ENGINEER_MODE_TELEPHONY_LIST_CNT; i++) {
        btn = lv_list_add_btn(list, NULL, lv_lang_get_text(engineer_mode_telephony_list[i].txtId));
        lv_watch_set_free_num(btn, i);
        lv_obj_add_style(btn, LV_BTN_PART_MAIN, &(ext->list_btn_st));
        lv_obj_set_event_cb(btn, telephony_btn_rel_event_cb);

        label = lv_obj_get_child(btn, NULL);
        lv_label_set_align(label, LV_LABEL_ALIGN_CENTER);
        lv_label_set_long_mode(label, LV_LABEL_LONG_BREAK);
        lv_obj_set_width(label, LV_HOR_RES - 10);
    }

    lv_obj_set_click(list, true);

    return obj;
}


/**********************
 *   STATIC FUNCTIONS
 **********************/
static void band_mode_ext_init(void)
{
    lv_band_mode_obj_ext_t * band_mode_ext = band_mode_get_ext();
    uint8_t lte_bitmap[2] = {};

    memset(band_mode_ext->gsm_band_sel, 0, BAND_MODE_GSM_CNT);
    memset(band_mode_ext->td_lte_band_sel, 0, BAND_MODE_TD_LTE_CNT);
    memset(band_mode_ext->fdd_lte_band_sel, 0, BAND_MODE_FDD_LTE_CNT);
    band_mode_ext->gsm_bitmap = 0;
    band_mode_ext->lte_bitmap = 0;

    UI_NV_Read_Req(NV_SECTION_UI_ENGINEER_MODE, 1, 1, &band_mode_ext->gsm_bitmap);
    UI_NV_Read_Req(NV_SECTION_UI_ENGINEER_MODE, 2, 2, lte_bitmap);
    band_mode_ext->lte_bitmap |= (uint16_t)lte_bitmap[1];
    band_mode_ext->lte_bitmap <<= 8;
    band_mode_ext->lte_bitmap |= (uint16_t)lte_bitmap[0];
}

static void telephony_btn_rel_event_cb(lv_obj_t * btn, lv_event_t e)
{
    if(LV_EVENT_CLICKED == e) {
        uint32_t num = lv_obj_get_user_data(btn).user_num;
        lv_obj_t * obj = NULL;

        obj = engineer_mode_item_watch_obj_create(NULL, engineer_mode_telephony_list[num].item_prepare_destory);
        if(NULL == obj) {
            printf("%s: obj is null\n", __FUNCTION__);
        } else {
            engineer_mode_item_title_create(obj, engineer_mode_telephony_list[num].txtId);
            engineer_mode_telephony_list[num].item_content_create(obj);
        }
    }
}

static void autoanswer_btn_press_event_cb(lv_obj_t * btn, lv_event_t e)
{
    nv_watch_engineer_mode_t engineermode;

    if(LV_EVENT_CLICKED == e) {
        lv_obj_t * label = lv_obj_get_child(btn, NULL);
        UI_NV_Read_Req(NV_SECTION_UI_ENGINEER_MODE, 0, sizeof(nv_watch_engineer_mode_t), (uint8_t *)&engineermode);
        if(AUTO_ANSWER_DISABLE == engineermode.autoanswerflg) {
            lv_label_set_text_id(label, WATCH_TEXT_ID_EMODE_TEL_AUTO_ANSWER_ENABLE);
            engineermode.autoanswerflg = AUTO_ANSWER_ENABLE;
        } else {
            lv_label_set_text_id(label, WATCH_TEXT_ID_EMODE_TEL_AUTO_ANSWER_DISABLE);
            engineermode.autoanswerflg = AUTO_ANSWER_DISABLE;
        }
        UI_NV_Write_Req(NV_SECTION_UI_ENGINEER_MODE, 0, sizeof(nv_watch_engineer_mode_t), (uint8_t *)&engineermode);
        lv_obj_add_style(label, LV_LABEL_PART_MAIN, &lv_watch_font20);
    }
}

static void auto_answer_create(lv_obj_t * par)
{
    lv_obj_t * btn = lv_btn_create(par, NULL);
    lv_obj_set_size(btn, LV_HOR_RES * 2 / 3, 30);
    lv_obj_align(btn, NULL, LV_ALIGN_IN_TOP_LEFT, 10, 35);
    lv_obj_set_style_local_radius(btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 5);
    lv_obj_set_event_cb(btn, autoanswer_btn_press_event_cb);
    lv_obj_t * label = lv_label_create(btn, NULL);
    nv_watch_engineer_mode_t               engineermode;
    UI_NV_Read_Req(NV_SECTION_UI_ENGINEER_MODE, 0, sizeof(nv_watch_engineer_mode_t), (uint8_t *)&engineermode);
    if(AUTO_ANSWER_DISABLE == engineermode.autoanswerflg) {
        lv_label_set_text_id(label, WATCH_TEXT_ID_EMODE_TEL_AUTO_ANSWER_DISABLE);
    } else {
        lv_label_set_text_id(label, WATCH_TEXT_ID_EMODE_TEL_AUTO_ANSWER_ENABLE);
    }
    lv_obj_add_style(label, LV_LABEL_PART_MAIN, &lv_watch_font20);
    lv_obj_align(btn, NULL, LV_ALIGN_IN_TOP_MID, 0, 60);
}

static void band_mode_create(lv_obj_t * par)
{
    lv_obj_t * title = lv_obj_get_child(par, NULL);
    lv_obj_t * list = lv_list_create(par, NULL);
    uint8_t i = 0;
    uint8_t lte_cnt = BAND_MODE_FDD_LTE_CNT + BAND_MODE_TD_LTE_CNT;
    lv_engineer_main_obj_ext_t * ext = engineer_mode_get_ext();
    char band_mode_list[BAND_MODE_GSM_CNT + BAND_MODE_FDD_LTE_CNT + BAND_MODE_TD_LTE_CNT][8] = {
        { "PGSM900" }, { "DCS1800" }, { "PCS1900" }, { "EGSM900" },
        { "GSM450" }, { "GSM480" }, { "GSM850" }, { "Band 1" },
        { "Band 2" }, { "Band 3" }, { "Band 4" }, { "Band 5" },
        { "Band 7" }, { "Band 13" }, { "Band 17" }, { "Band 20" },
        { "Band 38" }, { "Band 39" }, { "Band 40" }, { "Band 41" }
    };

    /*Allocate the object type specific extended data*/
    lv_band_mode_obj_ext_t * band_mode_ext = lv_obj_allocate_ext_attr(par, sizeof(lv_band_mode_obj_ext_t));
    LV_ASSERT_MEM(band_mode_ext);
    if(NULL == band_mode_ext) {
        return;
    }
    printf("%s watch_obj %p\n", __FUNCTION__, par);

    band_mode_ext_init();

    update_sel_gsm_band(band_mode_ext->gsm_bitmap);
    update_sel_lte_band(band_mode_ext->lte_bitmap);

    lv_page_set_edge_flash(list, true);
    lv_obj_add_style(list, LV_LIST_PART_EDGE_FLASH, &lv_watch_cont_opa1);
    lv_obj_add_style(list, LV_LIST_PART_SCROLLABLE, &ext->list_btn_inner_st);
    lv_obj_add_style(list, LV_LIST_PART_BG, &lv_watch_style_transp);
    lv_obj_align(list, title, LV_ALIGN_OUT_BOTTOM_MID, -20, 0);
    lv_obj_set_size(list, LV_HOR_RES, LV_VER_RES - lv_obj_get_height(title) - LV_VER_RES / 7);
    lv_watch_set_free_num(list, 0xF0);
    lv_watch_obj_add_element(list);

    lv_obj_t * btngsm = band_mode_list_add(list, (char *)lv_lang_get_text(WATCH_TEXT_ID_EMODE_TEL_GSM_MODE), false, NULL);
    lv_watch_set_free_num(btngsm, 0xFF);

    for(i = 0; i < BAND_MODE_GSM_CNT; i++) {
        lv_obj_t * btn = band_mode_list_add(list, band_mode_list[i], true, band_btn_rel_event_cb);
        lv_watch_set_free_num(btn, i);
        update_sel_band(btn, i);
    }

    lv_obj_t * btnlte = band_mode_list_add(list, (char *)lv_lang_get_text(WATCH_TEXT_ID_EMODE_TEL_LTE_MODE), false, NULL);
    lv_watch_set_free_num(btnlte, 0xFF);

    for(i = BAND_MODE_GSM_CNT; i < BAND_MODE_GSM_CNT + lte_cnt; i++) {
        lv_obj_t * btn = band_mode_list_add(list, band_mode_list[i], true, band_btn_rel_event_cb);
        lv_watch_set_free_num(btn, i);
        update_sel_band(btn, i);
    }

    band_mode_option_btn_create(par);
}

void watch_modem_lte_scell_info_process(MMI_MODEM_LTE_SCELL_INFO * scell)
{
    if(NULL == scell) {
        printf("scell is null in watch_modem_lte_scell_info_process\n");
        return;
    }
    char str[11] = {0};
    char lte_scell_info_list[50][20] = {
        { "mcc:" }, { "mnc:" }, { "tac:" }, { "phycellid:" },
        { "euarfcn:" }, { "uleuarfcn:" }, { "band:" }, { "dlbandwidth:" },
        { "rsrp:" }, { "rsrq:" }, { "sinr:" },
        { "errcmodestate:" }, { "emmstate:" }, { "servicestate:" }, { "singemmrejectcause:" },
        { "emmrejectcause:" }, { "mmegroupid:" }, { "mmecode:" },
        { "mtmsi:" }, { "scellpresent:" }, { "cellid:" }, { "subframeasstype:" },
        { "subframepatterns:" }, { "transmode:" }, { "mainrsrp:" }, { "diversityrsrp:" },
        { "mainrsrq:" }, { "diversityrsrq:" },
        { "rssi:" }, { "cqi:" }, { "pathloss:" }, { "tb0dltpt:" },
        { "tb1dltpt:" }, { "tb0dlpeaktpt:" }, { "tb1dlpeaktpt:" }, { "tb0ulpeaktpt:" },
        { "tb1ulpeaktpt:" }, { "dlthroughput:" },
        { "dlpeakthroughput:" }, { "averdlprb:" }, { "avercqitb0:" }, { "avercqitb1:" },
        { "rankindex:" }, { "granttotal:" }, { "ulthroughput:" }, { "ulpeakthroughput:" },
        { "currpuschtxpower:" }, { "averulprb:" }, { "dlbler:" }, { "ulbler:" }
    };
    lv_cell_info_obj_ext_t * cell_info_ext = cell_info_get_ext();
    LV_ASSERT_MEM(cell_info_ext);
    lv_obj_t * ta = cell_info_ext->ta;
    lv_textarea_set_text(ta, "");
    lv_textarea_add_text(ta, lte_scell_info_list[0]);
    memset(str, 0, 11);
    snprintf(str, 6, "%u", scell->mcc);
    lv_textarea_add_text(ta, str);
    printf("scell->mcc is %d\n", scell->mcc);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[1]);
    memset(str, 0, 11);
    snprintf(str, 6, "%u", scell->mnc);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[2]);
    memset(str, 0, 11);
    snprintf(str, 6, "%u", scell->tac);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[3]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->phycellid);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[4]);
    memset(str, 0, 11);
    snprintf(str, 6, "%u", scell->euarfcn);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[5]);
    memset(str, 0, 11);
    snprintf(str, 6, "%u", scell->uleuarfcn);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[6]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->band);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[7]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->dlbandwidth);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[8]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->rsrp);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[9]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->rsrq);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[10]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->sinr);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[11]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->errcmodestate);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[12]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->emmstate);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[13]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->servicestate);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[14]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->issingleemmrejectcause);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[15]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->emmrejectcause);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[16]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->mmegroupid);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[17]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->mmecode);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[18]);
    memset(str, 0, 11);
    snprintf(str, 11, "%u", scell->mtmsi);
    lv_textarea_add_text(ta, str);
    printf("scell->mtmsi is %u\n", scell->mtmsi);
    printf("str is %s\n", str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[19]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->scellpresent);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[20]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->cellid);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[21]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->subframeassigntype);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[22]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->specialsubframepatterns);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[23]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->transmode);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[24]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->mainrsrp);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[25]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->diversityrsrp);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[26]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->mainrsrq);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[27]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->diversityrsrq);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[28]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->rssi);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[29]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->cqi);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[30]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->pathloss);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[31]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->tb0dltpt);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[32]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->tb1dltpt);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[33]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->tb0dlpeaktpt);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[34]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->tb1dlpeaktpt);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[35]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->tb0ulpeaktpt);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[36]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->tb1ulpeaktpt);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[37]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->dlthroughput);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[38]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->dlpeakthroughput);
    lv_textarea_add_text(ta, str);
    printf("scell->dlpeakthroughput is %d\n", scell->dlpeakthroughput);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[39]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->averdlprb);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[40]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->avercqitb0);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[41]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->avercqitb1);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[42]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->rankindex);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[43]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->granttotal);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[44]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->ulthroughput);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[45]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->ulpeakthroughput);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[46]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->currpuschtxpower);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[47]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->averulprb);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[48]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->dlbler);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, lte_scell_info_list[49]);
    printf("lte_scell_info_list[49] is %s\n", lte_scell_info_list[49]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->ulbler);
    lv_textarea_add_text(ta, str);
    printf("scell->ulbler is %d\n", scell->ulbler);
    lv_textarea_add_text(ta, "\n");

    lv_textarea_set_cursor_pos(ta, 0);
}

void watch_modem_lte_ncell_info_process(uint8_t encell_num, MMI_MODEM_LTE_NCELL_INFO * encell)
{
    char lte_ncell_info_list[31][20] = {
        { "cellnumber:" },
        { "cell[1]index:" }, { "cell[1]euarfcn:" }, { "cell[1]cellid:" }, { "cell[1]rsrp:" }, { "cell[1]rsrq:" },
        { "cell[2]index:" }, { "cell[2]euarfcn:" }, { "cell[2]cellid:" }, { "cell[2]rsrp:" }, { "cell[2]rsrq:" },
        { "cell[3]index:" }, { "cell[3]euarfcn:" }, { "cell[3]cellid:" }, { "cell[3]rsrp:" }, { "cell[3]rsrq:" },
        { "cell[4]index:" }, { "cell[4]euarfcn:" }, { "cell[4]cellid:" }, { "cell[4]rsrp:" }, { "cell[4]rsrq:" },
        { "cell[5]index:" }, { "cell[5]euarfcn:" }, { "cell[5]cellid:" }, { "cell[5]rsrp:" }, { "cell[5]rsrq:" },
        { "cell[6]index:" }, { "cell[6]euarfcn:" }, { "cell[6]cellid:" }, { "cell[6]rsrp:" }, { "cell[6]rsrq:" },
    };
    uint8_t i;
    uint8_t j = 0;
    char str[11] = {0};
    lv_cell_info_obj_ext_t * cell_info_ext = cell_info_get_ext();
    LV_ASSERT_MEM(cell_info_ext);
    lv_obj_t * ta = cell_info_ext->ta;
    printf("encell_num is %d\n", encell_num);
    if(0 == encell_num) {
        return;
    }
    lv_textarea_set_text(ta, "");
    lv_textarea_add_text(ta, lte_ncell_info_list[0]);
    memset(str, 0, 11);
    snprintf(str, 4, "%u", encell_num);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");

    for(i = 0; i < encell_num; i++) {
        lv_textarea_add_text(ta, lte_ncell_info_list[++j]);
        printf("lte_ncell_info_list[%d] is %s\n", j, lte_ncell_info_list[j]);
        memset(str, 0, 11);
        snprintf(str, 4, "%u", encell[i].index);
        lv_textarea_add_text(ta, str);
        printf("encell[%d].index is %d\n", i, encell[i].index);
        lv_textarea_add_text(ta, "\n");
        lv_textarea_add_text(ta, lte_ncell_info_list[++j]);
        printf("lte_ncell_info_list[%d] is %s\n", j, lte_ncell_info_list[j]);
        memset(str, 0, 11);
        snprintf(str, 6, "%u", encell[i].euarfcn);
        lv_textarea_add_text(ta, str);
        printf("encell[%d].euarfcn is %d\n", i, encell[i].euarfcn);
        lv_textarea_add_text(ta, "\n");
        lv_textarea_add_text(ta, lte_ncell_info_list[++j]);
        printf("lte_ncell_info_list[%d] is %s\n", j, lte_ncell_info_list[j]);
        memset(str, 0, 11);
        snprintf(str, 10, "%u", encell[i].cellid);
        lv_textarea_add_text(ta, str);
        printf("encell[%d].cellid is %d\n", i, encell[i].cellid);
        lv_textarea_add_text(ta, "\n");
        lv_textarea_add_text(ta, lte_ncell_info_list[++j]);
        printf("lte_ncell_info_list[%d] is %s\n", j, lte_ncell_info_list[j]);
        memset(str, 0, 11);
        snprintf(str, 10, "%u", encell[i].rsrp);
        lv_textarea_add_text(ta, str);
        printf("encell[%d].rsrp is %d\n", i, encell[i].rsrp);
        lv_textarea_add_text(ta, "\n");
        lv_textarea_add_text(ta, lte_ncell_info_list[++j]);
        printf("lte_ncell_info_list[%d] is %s\n", j, lte_ncell_info_list[j]);
        memset(str, 0, 11);
        snprintf(str, 10, "%u", encell[i].rsrq);
        lv_textarea_add_text(ta, str);
        printf("encell[%d].rsrq is %d\n", i, encell[i].rsrq);
        lv_textarea_add_text(ta, "\n");
    }

    lv_textarea_set_cursor_pos(ta, 0);
}

void watch_modem_gsm_scell_info_process(MMI_MODEM_GSM_CELL_INFO * scell)
{
    char gsm_scell_info_list[7][15] = {
        { "mcc:" }, { "mnc:" }, { "lac:" }, { "scell arfcn:" },
        { "scell bsic:" }, { "scell cellid:" }, { "scell rxlev:" }
    };
    char str[11] = {0};
    lv_cell_info_obj_ext_t * cell_info_ext = cell_info_get_ext();
    LV_ASSERT_MEM(cell_info_ext);
    lv_obj_t * ta = cell_info_ext->ta;
    lv_textarea_set_text(ta, "");
    lv_textarea_add_text(ta, gsm_scell_info_list[0]);
    memset(str, 0, 11);
    snprintf(str, 6, "%u", scell->mcc);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, gsm_scell_info_list[1]);
    memset(str, 0, 11);
    snprintf(str, 6, "%u", scell->mnc);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, gsm_scell_info_list[2]);
    memset(str, 0, 11);
    snprintf(str, 6, "%u", scell->lac);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, gsm_scell_info_list[3]);
    memset(str, 0, 11);
    snprintf(str, 6, "%u", scell->arfcn);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, gsm_scell_info_list[4]);
    memset(str, 0, 11);
    snprintf(str, 4, "%u", scell->bsic);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, gsm_scell_info_list[5]);
    memset(str, 0, 11);
    snprintf(str, 10, "%u", scell->cell_id);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    lv_textarea_add_text(ta, gsm_scell_info_list[6]);
    memset(str, 0, 11);
    snprintf(str, 4, "%u", scell->rxlev);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");

    lv_textarea_set_cursor_pos(ta, 0);
}

void watch_modem_gsm_ncell_info_process(uint8_t gncell_num, MMI_MODEM_GSM_CELL_INFO * gncell)
{
    char gsm_ncell_info_list[28][20] = {
        { "cellnumber:" },   { "mcc:" },         { "mnc:" },           { "lac:" },
        { "cell[1]arfcn:" }, { "cell[1]bsic:" }, { "cell[1]cellid:" }, { "cell[1]rxlev:" },
        { "cell[2]arfcn:" }, { "cell[2]bsic:" }, { "cell[2]cellid:" }, { "cell[2]rxlev:" },
        { "cell[3]arfcn:" }, { "cell[3]bsic:" }, { "cell[3]cellid:" }, { "cell[3]rxlev:" },
        { "cell[4]arfcn:" }, { "cell[4]bsic:" }, { "cell[4]cellid:" }, { "cell[4]rxlev:" },
        { "cell[5]arfcn:" }, { "cell[5]bsic:" }, { "cell[5]cellid:" }, { "cell[5]rxlev:" },
        { "cell[6]arfcn:" }, { "cell[6]bsic:" }, { "cell[6]cellid:" }, { "cell[6]rxlev:" }
    };
    uint8_t i;
    uint8_t j = 3;
    char str[11] = {0};
    lv_cell_info_obj_ext_t * cell_info_ext = cell_info_get_ext();
    LV_ASSERT_MEM(cell_info_ext);
    lv_obj_t * ta = cell_info_ext->ta;
    printf("gncell_num is %d\n", gncell_num);
    if(0 == gncell_num) {
        return;
    }
    lv_textarea_set_text(ta, "");
    lv_textarea_add_text(ta, gsm_ncell_info_list[0]);
    memset(str, 0, 11);
    snprintf(str, 4, "%u", gncell_num);
    lv_textarea_add_text(ta, str);
    lv_textarea_add_text(ta, "\n");
    if(gncell_num) {
        lv_textarea_add_text(ta, gsm_ncell_info_list[1]);
        memset(str, 0, 11);
        snprintf(str, 6, "%u", gncell[0].mcc);
        lv_textarea_add_text(ta, str);
        lv_textarea_add_text(ta, "\n");
        lv_textarea_add_text(ta, gsm_ncell_info_list[2]);
        memset(str, 0, 11);
        snprintf(str, 6, "%u", gncell[0].mnc);
        lv_textarea_add_text(ta, str);
        lv_textarea_add_text(ta, "\n");
        lv_textarea_add_text(ta, gsm_ncell_info_list[3]);
        memset(str, 0, 11);
        snprintf(str, 6, "%u", gncell[0].lac);
        lv_textarea_add_text(ta, str);
        lv_textarea_add_text(ta, "\n");
    }

    for(i = 0; i < gncell_num; i++) {
        lv_textarea_add_text(ta, gsm_ncell_info_list[++j]);
        memset(str, 0, 11);
        snprintf(str, 6, "%u", gncell[i].arfcn);
        lv_textarea_add_text(ta, str);
        lv_textarea_add_text(ta, "\n");
        lv_textarea_add_text(ta, gsm_ncell_info_list[++j]);
        memset(str, 0, 11);
        snprintf(str, 4, "%u", gncell[i].bsic);
        lv_textarea_add_text(ta, str);
        lv_textarea_add_text(ta, "\n");
        lv_textarea_add_text(ta, gsm_ncell_info_list[++j]);
        memset(str, 0, 11);
        snprintf(str, 10, "%u", gncell[i].cell_id);
        lv_textarea_add_text(ta, str);
        lv_textarea_add_text(ta, "\n");
        lv_textarea_add_text(ta, gsm_ncell_info_list[++j]);
        memset(str, 0, 11);
        snprintf(str, 4, "%u", gncell[i].rxlev);
        lv_textarea_add_text(ta, str);
        lv_textarea_add_text(ta, "\n");
    }

    lv_textarea_set_cursor_pos(ta, 0);
}
void watch_modem_lte_cells_info_process(MMI_Modem_Lte_Cells_t * pltecells)
{
    lv_cell_info_obj_ext_t * cell_info_ext = cell_info_get_ext();
    if(NULL == cell_info_ext) {
        printf("cell_info_ext is NULL in watch_modem_lte_cells_info_process\n");
        lv_mem_free(pltecells);
        return;
    }

    printf("cell_info_ext->cell_info_type is %d\n", cell_info_ext->cell_info_type);

    switch(cell_info_ext->cell_info_type) {
        case LTE_SCELL_INFO:
            watch_modem_lte_scell_info_process(&pltecells->scell);
            break;

        case LTE_NCELL_INFO:
            watch_modem_lte_ncell_info_process(pltecells->encell_num, pltecells->encell);
            break;

        case LTE_IRAT_NCELL_INFO:
            watch_modem_gsm_ncell_info_process(pltecells->gncell_num, pltecells->gncell);
            break;

        default:
            break;
    }
    lv_mem_free(pltecells);
}

void watch_modem_gsm_cells_info_process(MMI_Modem_Gsm_Cells_t * pgsmcells)
{
    lv_cell_info_obj_ext_t * cell_info_ext = cell_info_get_ext();
    if(NULL == cell_info_ext) {
        printf("cell_info_ext is NULL in watch_modem_gsm_cells_info_process\n");
        lv_mem_free(pgsmcells);
        return;
    }

    printf("cell_info_ext->cell_info_type is %d\n", cell_info_ext->cell_info_type);

    switch(cell_info_ext->cell_info_type) {
        case GSM_SCELL_INFO:
            watch_modem_gsm_scell_info_process(&pgsmcells->scell);
            break;

        case GSM_NCELL_INFO:
            watch_modem_gsm_ncell_info_process(pgsmcells->gncell_num, pgsmcells->gncell);
            break;

        case GSM_IRAT_NCELL_INFO:
            watch_modem_lte_ncell_info_process(pgsmcells->encell_num, pgsmcells->encell);
            break;

        default:
            break;
    }
    lv_mem_free(pgsmcells);
}
static void cell_info_task(lv_task_t * task)
{
    watch_modem_adp_get_cell_info_req();
}
static void lte_scell_btn_rel_action(lv_obj_t * par)
{
    char lte_scell_info_list[50][20] = {
        { "mcc:" }, { "mnc:" }, { "tac:" }, { "phycellid:" },
        { "euarfcn:" }, { "uleuarfcn:" }, { "band:" }, { "dlbandwidth:" },
        { "rsrp:" }, { "rsrq:" }, { "sinr:" },
        { "errcmodestate:" }, { "emmstate:" }, { "servicestate:" }, { "singemmrejectcause:" },
        { "emmrejectcause:" }, { "mmegroupid:" }, { "mmecode:" },
        { "mtmsi:" }, { "scellpresent:" }, { "cellid:" }, { "subframeasstype:" },
        { "subframepatterns:" }, { "transmode:" }, { "mainrsrp:" }, { "diversityrsrp:" },
        { "mainrsrq:" }, { "diversityrsrq:" },
        { "rssi:" }, { "cqi:" }, { "pathloss:" }, { "tb0dltpt:" },
        { "tb1dltpt:" }, { "tb0dlpeaktpt:" }, { "tb1dlpeaktpt:" }, { "tb0ulpeaktpt:" },
        { "tb1ulpeaktpt:" }, { "dlthroughput:" },
        { "dlpeakthroughput:" }, { "averdlprb:" }, { "avercqitb0:" }, { "avercqitb1:" },
        { "rankindex:" }, { "granttotal:" }, { "ulthroughput:" }, { "ulpeakthroughput:" },
        { "currpuschtxpower:" }, { "averulprb:" }, { "dlbler:" }, { "ulbler:" }
    };
    uint8_t i;
    lv_obj_t * title = lv_obj_get_child(par, NULL);
    lv_obj_t * ta = lv_textarea_create(par, NULL);
    LV_ASSERT_MEM(ta);

    lv_obj_align(ta, title, LV_ALIGN_OUT_BOTTOM_MID, -10, 0);
    lv_obj_set_size(ta, LV_HOR_RES, LV_VER_RES - lv_obj_get_height(title));

    lv_obj_add_style(ta, LV_TEXTAREA_PART_BG, &lv_watch_style_transp);

    lv_obj_add_style(lv_textarea_get_label(ta), LV_LABEL_PART_MAIN, &lv_watch_font20);
    lv_textarea_set_text_align(ta, LV_LABEL_ALIGN_LEFT);
    lv_textarea_set_cursor_hidden(ta, true);
    lv_textarea_set_text(ta, "");

    for(i = 0; i < 50; i++) {
        lv_textarea_add_text(ta, lte_scell_info_list[i]);
        lv_textarea_add_char(ta, '0');
        lv_textarea_add_text(ta, "\n");
    }
    lv_textarea_set_cursor_pos(ta, 0);
    lv_watch_obj_add_element(ta);
    lv_watch_obj_add_element(lv_page_get_scrl(ta));
    /*Allocate the object type specific extended data*/
    lv_cell_info_obj_ext_t * cell_info_ext = lv_obj_allocate_ext_attr(par, sizeof(lv_cell_info_obj_ext_t));
    LV_ASSERT_MEM(cell_info_ext);

    cell_info_ext->ta = ta;
    cell_info_ext->cell_info_type = LTE_SCELL_INFO;
    watch_modem_adp_get_cell_info_req();
    cell_info_ext->cell_info_task_p = lv_task_create(cell_info_task, 10000, LV_TASK_PRIO_MID, NULL);
}

static void lte_ncell_btn_rel_action(lv_obj_t * par)
{
    char lte_ncell_info_list[31][20] = {
        { "cellnumber:" },
        { "cell[1]index:" }, { "cell[1]euarfcn:" }, { "cell[1]cellid:" }, { "cell[1]rsrp:" }, { "cell[1]rsrq:" },
        { "cell[2]index:" }, { "cell[2]euarfcn:" }, { "cell[2]cellid:" }, { "cell[2]rsrp:" }, { "cell[2]rsrq:" },
        { "cell[3]index:" }, { "cell[3]euarfcn:" }, { "cell[3]cellid:" }, { "cell[3]rsrp:" }, { "cell[3]rsrq:" },
        { "cell[4]index:" }, { "cell[4]euarfcn:" }, { "cell[4]cellid:" }, { "cell[4]rsrp:" }, { "cell[4]rsrq:" },
        { "cell[5]index:" }, { "cell[5]euarfcn:" }, { "cell[5]cellid:" }, { "cell[5]rsrp:" }, { "cell[5]rsrq:" },
        { "cell[6]index:" }, { "cell[6]euarfcn:" }, { "cell[6]cellid:" }, { "cell[6]rsrp:" }, { "cell[6]rsrq:" },
    };
    uint8_t i;
    lv_obj_t * title = lv_obj_get_child(par, NULL);
    lv_obj_t * ta = lv_textarea_create(par, NULL);
    LV_ASSERT_MEM(ta);

    lv_obj_align(ta, title, LV_ALIGN_OUT_BOTTOM_MID, -10, 0);
    lv_obj_set_size(ta, LV_HOR_RES, LV_VER_RES - lv_obj_get_height(title));

    lv_obj_add_style(ta, LV_TEXTAREA_PART_BG, &lv_watch_style_transp);
    lv_obj_add_style(lv_textarea_get_label(ta), LV_LABEL_PART_MAIN, &lv_watch_font20);
    lv_textarea_set_text_align(ta, LV_LABEL_ALIGN_LEFT);
    lv_textarea_set_cursor_hidden(ta, true);
    lv_textarea_set_text(ta, "");

    for(i = 0; i < 31; i++) {
        lv_textarea_add_text(ta, lte_ncell_info_list[i]);
        lv_textarea_add_char(ta, '0');
        lv_textarea_add_text(ta, "\n");
    }
    lv_textarea_set_cursor_pos(ta, 0);
    lv_watch_obj_add_element(ta);
    lv_watch_obj_add_element(lv_page_get_scrl(ta));
    /*Allocate the object type specific extended data*/
    lv_cell_info_obj_ext_t * cell_info_ext = lv_obj_allocate_ext_attr(par, sizeof(lv_cell_info_obj_ext_t));
    LV_ASSERT_MEM(cell_info_ext);

    cell_info_ext->ta = ta;
    cell_info_ext->cell_info_type = LTE_NCELL_INFO;
    watch_modem_adp_get_cell_info_req();
    cell_info_ext->cell_info_task_p = lv_task_create(cell_info_task, 10000, LV_TASK_PRIO_MID, NULL);
}

static void lte_irat_ncell_btn_rel_action(lv_obj_t * par)
{
    char gsm_ncell_info_list[28][20] = {
        { "cellnumber:" },   { "mcc:" },         { "mnc:" },           { "lac:" },
        { "cell[1]arfcn:" }, { "cell[1]bsic:" }, { "cell[1]cellid:" }, { "cell[1]rxlev:" },
        { "cell[2]arfcn:" }, { "cell[2]bsic:" }, { "cell[2]cellid:" }, { "cell[2]rxlev:" },
        { "cell[3]arfcn:" }, { "cell[3]bsic:" }, { "cell[3]cellid:" }, { "cell[3]rxlev:" },
        { "cell[4]arfcn:" }, { "cell[4]bsic:" }, { "cell[4]cellid:" }, { "cell[4]rxlev:" },
        { "cell[5]arfcn:" }, { "cell[5]bsic:" }, { "cell[5]cellid:" }, { "cell[5]rxlev:" },
        { "cell[6]arfcn:" }, { "cell[6]bsic:" }, { "cell[6]cellid:" }, { "cell[6]rxlev:" }
    };
    uint8_t i;
    lv_obj_t * title = lv_obj_get_child(par, NULL);
    lv_obj_t * ta = lv_textarea_create(par, NULL);
    LV_ASSERT_MEM(ta);

    lv_obj_align(ta, title, LV_ALIGN_OUT_BOTTOM_MID, -10, 0);
    lv_obj_set_size(ta, LV_HOR_RES, LV_VER_RES - lv_obj_get_height(title));

    lv_obj_add_style(ta, LV_TEXTAREA_PART_BG, &lv_watch_style_transp);
    lv_obj_add_style(lv_textarea_get_label(ta), LV_LABEL_PART_MAIN, &lv_watch_font20);
    lv_textarea_set_text_align(ta, LV_LABEL_ALIGN_LEFT);
    lv_textarea_set_cursor_hidden(ta, true);
    lv_textarea_set_text(ta, "");

    for(i = 0; i < 28; i++) {
        lv_textarea_add_text(ta, gsm_ncell_info_list[i]);
        lv_textarea_add_char(ta, '0');
        lv_textarea_add_text(ta, "\n");
    }
    lv_textarea_set_cursor_pos(ta, 0);
    lv_watch_obj_add_element(ta);
    lv_watch_obj_add_element(lv_page_get_scrl(ta));
    /*Allocate the object type specific extended data*/
    lv_cell_info_obj_ext_t * cell_info_ext = lv_obj_allocate_ext_attr(par, sizeof(lv_cell_info_obj_ext_t));
    LV_ASSERT_MEM(cell_info_ext);

    cell_info_ext->ta = ta;
    cell_info_ext->cell_info_type = LTE_IRAT_NCELL_INFO;
    watch_modem_adp_get_cell_info_req();
    cell_info_ext->cell_info_task_p = lv_task_create(cell_info_task, 10000, LV_TASK_PRIO_MID, NULL);
}

static void gsm_scell_btn_rel_action(lv_obj_t * par)
{
    char gsm_scell_info_list[7][15] = {
        { "mcc:" }, { "mnc:" }, { "lac:" }, { "scell arfcn:" },
        { "scell bsic:" }, { "scell cellid:" }, { "scell rxlev:" }
    };
    uint8_t i;
    lv_obj_t * title = lv_obj_get_child(par, NULL);
    lv_obj_t * ta = lv_textarea_create(par, NULL);
    LV_ASSERT_MEM(ta);

    lv_obj_align(ta, title, LV_ALIGN_OUT_BOTTOM_MID, -10, 0);
    lv_obj_set_size(ta, LV_HOR_RES, LV_VER_RES - lv_obj_get_height(title));

    lv_obj_add_style(ta, LV_TEXTAREA_PART_BG, &lv_watch_style_transp);
    lv_obj_add_style(lv_textarea_get_label(ta), LV_LABEL_PART_MAIN, &lv_watch_font20);
    lv_textarea_set_text_align(ta, LV_LABEL_ALIGN_LEFT);
    lv_textarea_set_cursor_hidden(ta, true);
    lv_textarea_set_text(ta, "");

    for(i = 0; i < 7; i++) {
        lv_textarea_add_text(ta, gsm_scell_info_list[i]);
        lv_textarea_add_char(ta, '0');
        lv_textarea_add_text(ta, "\n");
    }
    lv_textarea_set_cursor_pos(ta, 0);
    lv_watch_obj_add_element(ta);
    lv_watch_obj_add_element(lv_page_get_scrl(ta));
    /*Allocate the object type specific extended data*/
    lv_cell_info_obj_ext_t * cell_info_ext = lv_obj_allocate_ext_attr(par, sizeof(lv_cell_info_obj_ext_t));
    LV_ASSERT_MEM(cell_info_ext);

    cell_info_ext->ta = ta;
    cell_info_ext->cell_info_type = GSM_SCELL_INFO;
    watch_modem_adp_get_cell_info_req();
    cell_info_ext->cell_info_task_p = lv_task_create(cell_info_task, 10000, LV_TASK_PRIO_MID, NULL);
}

static void gsm_ncell_btn_rel_action(lv_obj_t * par)
{
    char gsm_ncell_info_list[28][20] = {
        { "cellnumber:" },   { "mcc:" },         { "mnc:" },           { "lac:" },
        { "cell[1]arfcn:" }, { "cell[1]bsic:" }, { "cell[1]cellid:" }, { "cell[1]rxlev:" },
        { "cell[2]arfcn:" }, { "cell[2]bsic:" }, { "cell[2]cellid:" }, { "cell[2]rxlev:" },
        { "cell[3]arfcn:" }, { "cell[3]bsic:" }, { "cell[3]cellid:" }, { "cell[3]rxlev:" },
        { "cell[4]arfcn:" }, { "cell[4]bsic:" }, { "cell[4]cellid:" }, { "cell[4]rxlev:" },
        { "cell[5]arfcn:" }, { "cell[5]bsic:" }, { "cell[5]cellid:" }, { "cell[5]rxlev:" },
        { "cell[6]arfcn:" }, { "cell[6]bsic:" }, { "cell[6]cellid:" }, { "cell[6]rxlev:" }
    };
    uint8_t i;
    lv_obj_t * title = lv_obj_get_child(par, NULL);
    lv_obj_t * ta = lv_textarea_create(par, NULL);
    LV_ASSERT_MEM(ta);

    lv_obj_align(ta, title, LV_ALIGN_OUT_BOTTOM_MID, -10, 0);
    lv_obj_set_size(ta, LV_HOR_RES, LV_VER_RES - lv_obj_get_height(title));

    lv_obj_add_style(ta, LV_TEXTAREA_PART_BG, &lv_watch_style_transp);
    lv_obj_add_style(lv_textarea_get_label(ta), LV_LABEL_PART_MAIN, &lv_watch_font20);
    lv_textarea_set_text_align(ta, LV_LABEL_ALIGN_LEFT);
    lv_textarea_set_cursor_hidden(ta, true);
    lv_textarea_set_text(ta, "");

    for(i = 0; i < 28; i++) {
        lv_textarea_add_text(ta, gsm_ncell_info_list[i]);
        lv_textarea_add_char(ta, '0');
        lv_textarea_add_text(ta, "\n");
    }
    lv_textarea_set_cursor_pos(ta, 0);
    lv_watch_obj_add_element(ta);
    lv_watch_obj_add_element(lv_page_get_scrl(ta));
    /*Allocate the object type specific extended data*/
    lv_cell_info_obj_ext_t * cell_info_ext = lv_obj_allocate_ext_attr(par, sizeof(lv_cell_info_obj_ext_t));
    LV_ASSERT_MEM(cell_info_ext);

    cell_info_ext->ta = ta;
    cell_info_ext->cell_info_type = GSM_NCELL_INFO;
    watch_modem_adp_get_cell_info_req();
    cell_info_ext->cell_info_task_p = lv_task_create(cell_info_task, 10000, LV_TASK_PRIO_MID, NULL);
}

static void gsm_irat_ncell_btn_rel_action(lv_obj_t * par)
{
    char lte_ncell_info_list[31][20] = {
        { "cellnumber:" },
        { "cell[1]index:" }, { "cell[1]euarfcn:" }, { "cell[1]cellid:" }, { "cell[1]rsrp:" }, { "cell[1]rsrq:" },
        { "cell[2]index:" }, { "cell[2]euarfcn:" }, { "cell[2]cellid:" }, { "cell[2]rsrp:" }, { "cell[2]rsrq:" },
        { "cell[3]index:" }, { "cell[3]euarfcn:" }, { "cell[3]cellid:" }, { "cell[3]rsrp:" }, { "cell[3]rsrq:" },
        { "cell[4]index:" }, { "cell[4]euarfcn:" }, { "cell[4]cellid:" }, { "cell[4]rsrp:" }, { "cell[4]rsrq:" },
        { "cell[5]index:" }, { "cell[5]euarfcn:" }, { "cell[5]cellid:" }, { "cell[5]rsrp:" }, { "cell[5]rsrq:" },
        { "cell[6]index:" }, { "cell[6]euarfcn:" }, { "cell[6]cellid:" }, { "cell[6]rsrp:" }, { "cell[6]rsrq:" },
    };
    uint8_t i;
    lv_obj_t * title = lv_obj_get_child(par, NULL);
    lv_obj_t * ta = lv_textarea_create(par, NULL);
    LV_ASSERT_MEM(ta);

    lv_obj_align(ta, title, LV_ALIGN_OUT_BOTTOM_MID, -10, 0);
    lv_obj_set_size(ta, LV_HOR_RES, LV_VER_RES - lv_obj_get_height(title));

    lv_obj_add_style(ta, LV_TEXTAREA_PART_BG, &lv_watch_style_transp);
    lv_obj_add_style(lv_textarea_get_label(ta), LV_LABEL_PART_MAIN, &lv_watch_font20);
    lv_textarea_set_text_align(ta, LV_LABEL_ALIGN_LEFT);
    lv_textarea_set_cursor_hidden(ta, true);
    lv_textarea_set_text(ta, "");

    for(i = 0; i < 31; i++) {
        lv_textarea_add_text(ta, lte_ncell_info_list[i]);
        lv_textarea_add_char(ta, '0');
        lv_textarea_add_text(ta, "\n");
    }
    lv_textarea_set_cursor_pos(ta, 0);
    lv_watch_obj_add_element(ta);
    lv_watch_obj_add_element(lv_page_get_scrl(ta));
    /*Allocate the object type specific extended data*/
    lv_cell_info_obj_ext_t * cell_info_ext = lv_obj_allocate_ext_attr(par, sizeof(lv_cell_info_obj_ext_t));
    LV_ASSERT_MEM(cell_info_ext);

    cell_info_ext->ta = ta;
    cell_info_ext->cell_info_type = GSM_IRAT_NCELL_INFO;
    watch_modem_adp_get_cell_info_req();
    cell_info_ext->cell_info_task_p = lv_task_create(cell_info_task, 10000, LV_TASK_PRIO_MID, NULL);
}

static void cell_info_btn_rel_event_cb(lv_obj_t * btn, lv_event_t e)
{
    if(LV_EVENT_CLICKED == e) {
        uint32_t num = lv_obj_get_user_data(btn).user_num;
        lv_obj_t * obj = NULL;

        obj = cell_info_watch_obj_create(NULL, telephony_cell_info_list[num].item_prepare_destory);
        if(NULL == obj) {
            printf("%s: obj is null\n", __FUNCTION__);
        } else {
            engineer_mode_item_title_create(obj, telephony_cell_info_list[num].txtId);
            telephony_cell_info_list[num].item_content_create(obj);
        }
    }
}
static void lte_info_create(lv_obj_t * par)
{
    lv_obj_t * title = lv_obj_get_child(par, NULL);
    lv_obj_t * list = lv_list_create(par, NULL);
    lv_obj_set_size(list, LV_HOR_RES, LV_VER_RES - lv_obj_get_height(title) - 10);
    lv_page_set_edge_flash(list, true);
    lv_obj_add_style(list, LV_LIST_PART_EDGE_FLASH, &lv_watch_cont_opa1);
    lv_obj_align(list, title, LV_ALIGN_OUT_BOTTOM_MID, 0, 20);

    lv_engineer_main_obj_ext_t * ext = engineer_mode_get_ext();
    lv_obj_add_style(list, LV_LIST_PART_BG,  &lv_watch_style_transp);

    uint8_t i = 0;
    lv_obj_t * btn;
    lv_obj_t * label;
    for(i = 0; i < TELEPHONY_LTE_CELL_INFO_LIST_CNT; i++) {
        btn = lv_list_add_btn(list, NULL, lv_lang_get_text(telephony_cell_info_list[i].txtId));
        lv_watch_set_free_num(btn, i);
        lv_obj_add_style(btn, LV_BTN_PART_MAIN, &(ext->list_btn_st));
        lv_obj_set_event_cb(btn, cell_info_btn_rel_event_cb);

        label = lv_obj_get_child(btn, NULL);
        lv_label_set_align(label, LV_LABEL_ALIGN_CENTER);
        lv_label_set_long_mode(label, LV_LABEL_LONG_BREAK);
        lv_obj_set_width(label, LV_HOR_RES - 10);
    }

    lv_obj_set_click(list, true);
    lv_watch_obj_add_element(list);
    lv_watch_obj_add_element(lv_page_get_scrl(list));
}

static void gsm_info_create(lv_obj_t * par)
{
    lv_obj_t * title = lv_obj_get_child(par, NULL);
    lv_obj_t * list = lv_list_create(par, NULL);
    lv_obj_set_size(list, LV_HOR_RES, LV_VER_RES - lv_obj_get_height(title) - 10);
    lv_page_set_edge_flash(list, true);
    lv_obj_add_style(list, LV_LIST_PART_EDGE_FLASH, &lv_watch_cont_opa1);
    lv_obj_align(list, title, LV_ALIGN_OUT_BOTTOM_MID, 0, 20);

    lv_engineer_main_obj_ext_t * ext = engineer_mode_get_ext();
    lv_obj_add_style(list, LV_LIST_PART_BG,  &lv_watch_style_transp);

    uint8_t i = 0;
    lv_obj_t * btn;
    lv_obj_t * label;
    for(i = TELEPHONY_LTE_CELL_INFO_LIST_CNT; i < TELEPHONY_LTE_CELL_INFO_LIST_CNT + TELEPHONY_GSM_CELL_INFO_LIST_CNT; i++) {
        btn = lv_list_add_btn(list, NULL, lv_lang_get_text(telephony_cell_info_list[i].txtId));
        lv_watch_set_free_num(btn, i);
        lv_obj_add_style(btn, LV_BTN_PART_MAIN, &(ext->list_btn_st));
        lv_obj_set_event_cb(btn, cell_info_btn_rel_event_cb);

        label = lv_obj_get_child(btn, NULL);
        lv_label_set_align(label, LV_LABEL_ALIGN_CENTER);
        lv_label_set_long_mode(label, LV_LABEL_LONG_BREAK);
        lv_obj_set_width(label, LV_HOR_RES - 10);
    }

    lv_obj_set_click(list, true);
    lv_watch_obj_add_element(list);
    lv_watch_obj_add_element(lv_page_get_scrl(list));
}

static void gps_create(lv_obj_t * par)
{
}

static void sn_info_create(lv_obj_t * par)
{
    lv_obj_t * rslt_label = lv_label_create(par, NULL);
    lv_obj_add_style(rslt_label, LV_LABEL_PART_MAIN, &lv_watch_font30);
    lv_label_set_long_mode(rslt_label, LV_LABEL_LONG_BREAK);
    lv_obj_set_width(rslt_label, LV_HOR_RES * 2 / 3);
    lv_label_set_text(rslt_label, "");

    lv_engineer_main_obj_ext_t * ext = engineer_mode_get_ext();
    ext->label_rslt = rslt_label;

    watch_modem_adp_get_sn_info_req();
}

static void calibration_query_create(lv_obj_t * par)
{
    lv_obj_t * rslt_label = lv_label_create(par, NULL);
    lv_obj_add_style(rslt_label, LV_LABEL_PART_MAIN, &lv_watch_font30);
    lv_label_set_text(rslt_label, "");

    lv_engineer_main_obj_ext_t * ext = engineer_mode_get_ext();
    ext->label_rslt = rslt_label;

    watch_modem_adp_get_calibration_info_req();
}

static lv_band_mode_obj_ext_t * band_mode_get_ext(void)
{
    lv_obj_t * activity_obj = lv_watch_get_activity_obj(ACT_ID_ENGINEER_MODE_ITEM);
    if(activity_obj == NULL) return NULL;

    lv_obj_t * watch_obj;
    lv_watch_get_child_obj(activity_obj, lv_watch_obj_signal, &watch_obj);
    if(watch_obj == NULL) return NULL;

    printf("%s watch_obj %p\n", __FUNCTION__, watch_obj);

    if(watch_obj) {
        lv_band_mode_obj_ext_t * ext = lv_obj_get_ext_attr(watch_obj);
        return ext;
    }
    return NULL;
}

static void telephony_prepare_destory(lv_obj_t * activity_obj)
{
    lv_watch_png_cache_all_free();
}

static lv_obj_t * band_mode_list_add(lv_obj_t * list, char * str, bool cb_need, lv_event_cb_t event_cb)
{
    /*Create a list element with the image an the text*/
    lv_obj_t * btn = lv_btn_create(list, NULL);

    /*Save the original signal function because it will be required in `lv_list_btn_signal`*/
    lv_list_set_ancestor_btn_signal(btn);

    lv_engineer_main_obj_ext_t * ext = engineer_mode_get_ext();
    /*Set the default styles*/
    if(true == cb_need) {
        lv_obj_add_style(btn, LV_BTN_PART_MAIN, &lv_watch_style_transp);
    } else {
        lv_obj_add_style(btn, LV_BTN_PART_MAIN, &ext->list_btn_st);
    }

    lv_obj_set_event_cb(btn, event_cb);
    lv_page_glue_obj(btn, true);
    lv_btn_set_layout(btn, LV_LAYOUT_ROW_MID);
    lv_btn_set_fit2(btn, LV_FIT_NONE, LV_FIT_TIGHT);
    lv_obj_add_protect(btn, LV_PROTECT_PRESS_LOST);
    lv_obj_set_signal_cb(btn, lv_list_get_listbtn_signal());

    /*Make the size adjustment*/
    lv_coord_t w = lv_obj_get_width(list);
    uint8_t pad_w = w - lv_obj_get_style_pad_left(btn, LV_BTN_PART_MAIN) - lv_obj_get_style_pad_right(btn, LV_BTN_PART_MAIN);
    lv_obj_set_size(btn, pad_w, 30);
    lv_obj_set_x(btn, lv_obj_get_style_pad_left(btn, LV_BTN_PART_MAIN));
    lv_watch_obj_add_element(btn);

    if(true == cb_need) {
        lv_obj_t * img = lv_img_create(btn, NULL);
        lv_img_set_src(img, ICON_UNCHECK);
        lv_obj_align(img, btn, LV_ALIGN_IN_LEFT_MID, 10, 0);
        lv_watch_obj_add_element(img);

        lv_obj_t * label = lv_label_create(btn, NULL);
        lv_obj_add_style(label, LV_LABEL_PART_MAIN, &lv_watch_font20);
        lv_label_set_text(label, str);
        lv_obj_align(label, img, LV_ALIGN_OUT_RIGHT_MID, 10, 0);
        lv_watch_obj_add_element(label);
    } else {
        lv_obj_t * label = lv_label_create(btn, NULL);
        lv_obj_add_style(label, LV_LABEL_PART_MAIN, &lv_watch_font20);
        lv_label_set_text(label, str);
        lv_obj_align(label, btn, LV_ALIGN_IN_LEFT_MID, 10, 0);
        lv_watch_obj_add_element(label);
    }
    return btn;
}

static void update_sel_band(lv_obj_t * btn, uint32_t index)
{
    lv_band_mode_obj_ext_t * band_mode_ext = band_mode_get_ext();
    lv_obj_t * img = lv_obj_get_child_back(btn, NULL);

    if(BAND_MODE_GSM_CNT > index) {
        if(true == band_mode_ext->gsm_band_sel[index]) {
            lv_img_set_src(img, ICON_CHECK_TEST);
        } else {
            lv_img_set_src(img, ICON_UNCHECK);
        }
    } else if((BAND_MODE_GSM_CNT <= index) && ((BAND_MODE_GSM_CNT + BAND_MODE_FDD_LTE_CNT) > index)) {
        if(true == band_mode_ext->fdd_lte_band_sel[index - BAND_MODE_GSM_CNT]) {
            lv_img_set_src(img, ICON_CHECK_TEST);
        } else {
            lv_img_set_src(img, ICON_UNCHECK);
        }
    } else {
        if(true == band_mode_ext->td_lte_band_sel[index - BAND_MODE_GSM_CNT - BAND_MODE_FDD_LTE_CNT]) {
            lv_img_set_src(img, ICON_CHECK_TEST);
        } else {
            lv_img_set_src(img, ICON_UNCHECK);
        }
    }
}

static void update_sel_gsm_band(uint8_t gsm_bitmap)
{
    uint8_t i = 0;
    lv_band_mode_obj_ext_t * band_mode_ext = band_mode_get_ext();

    for(i = 0; i < BAND_MODE_GSM_CNT; i++) {
        if(0x01 & (gsm_bitmap >> i)) {
            band_mode_ext->gsm_band_sel[i] = true;
        } else {
            band_mode_ext->gsm_band_sel[i] = false;
        }
    }
}

static void update_sel_lte_band(uint16_t lte_bitmap)
{
    uint8_t i = 0;
    lv_band_mode_obj_ext_t * band_mode_ext = band_mode_get_ext();

    for(i = 0; i < BAND_MODE_FDD_LTE_CNT; i++) {
        if(0x01 & (lte_bitmap >> i)) {
            band_mode_ext->fdd_lte_band_sel[i] = true;
        } else {
            band_mode_ext->fdd_lte_band_sel[i] = false;
        }
    }

    for(i = BAND_MODE_FDD_LTE_CNT; i < BAND_MODE_FDD_LTE_CNT + BAND_MODE_TD_LTE_CNT; i++) {
        if(0x01 & (lte_bitmap >> i)) {
            band_mode_ext->td_lte_band_sel[i - BAND_MODE_FDD_LTE_CNT] = true;
        } else {
            band_mode_ext->td_lte_band_sel[i - BAND_MODE_FDD_LTE_CNT] = false;
        }
    }
}

static uint8_t update_gsm_band_bitmap(void)
{
    uint8_t i = 0;
    uint8_t bitmap = 0;
    lv_band_mode_obj_ext_t * band_mode_ext = band_mode_get_ext();

    for(i = 0; i < BAND_MODE_GSM_CNT; i++) {
        if(true == band_mode_ext->gsm_band_sel[i]) {
            bitmap |= (0x01 << i);
        } else {
            bitmap |= (0x00 << i);
        }
    }

    return bitmap;
}

static uint16_t update_lte_band_bitmap(void)
{
    uint8_t i = 0;
    uint16_t bitmap = 0;
    lv_band_mode_obj_ext_t * band_mode_ext = band_mode_get_ext();

    for(i = 0; i < BAND_MODE_FDD_LTE_CNT; i++) {
        if(true == band_mode_ext->fdd_lte_band_sel[i]) {
            bitmap |= (0x0001 << i);
        } else {
            bitmap |= (0x0000 << i);
        }
    }
    for(i = BAND_MODE_FDD_LTE_CNT; i < BAND_MODE_FDD_LTE_CNT + BAND_MODE_TD_LTE_CNT; i++) {
        if(true == band_mode_ext->td_lte_band_sel[i - BAND_MODE_FDD_LTE_CNT]) {
            bitmap |= (0x0001 << i);
        } else {
            bitmap |= (0x0000 << i);
        }
    }

    return bitmap;
}

static void band_btn_rel_event_cb(lv_obj_t * btn, lv_event_t e)
{
    if(LV_EVENT_CLICKED == e) {
        lv_band_mode_obj_ext_t * band_mode_ext = band_mode_get_ext();
        uint32_t num = lv_obj_get_user_data(btn).user_num;

        if(BAND_MODE_GSM_CNT > num) {
            if(true == band_mode_ext->gsm_band_sel[num]) {
                band_mode_ext->gsm_band_sel[num] = false;
            } else {
                band_mode_ext->gsm_band_sel[num] = true;
            }
        } else if((BAND_MODE_GSM_CNT <= num) && ((BAND_MODE_GSM_CNT + BAND_MODE_FDD_LTE_CNT) > num)) {
            if(true == band_mode_ext->fdd_lte_band_sel[num - BAND_MODE_GSM_CNT]) {
                band_mode_ext->fdd_lte_band_sel[num - BAND_MODE_GSM_CNT] = false;
            } else {
                band_mode_ext->fdd_lte_band_sel[num - BAND_MODE_GSM_CNT] = true;
            }
        } else {
            if(true == band_mode_ext->td_lte_band_sel[num - BAND_MODE_GSM_CNT - BAND_MODE_FDD_LTE_CNT]) {
                band_mode_ext->td_lte_band_sel[num - BAND_MODE_GSM_CNT - BAND_MODE_FDD_LTE_CNT] = false;
            } else {
                band_mode_ext->td_lte_band_sel[num - BAND_MODE_GSM_CNT - BAND_MODE_FDD_LTE_CNT] = true;
            }
        }

        update_sel_band(btn, num);
    }
}

static void band_mode_option_btn_create(lv_obj_t * par)
{
    lv_obj_t * set_btn = lv_btn_create(par, NULL);
    lv_obj_t * set_label = lv_label_create(set_btn, NULL);

    lv_obj_set_style_local_radius(set_btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 5);
    lv_obj_set_style_local_border_side(set_btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_BORDER_SIDE_FULL);
    lv_obj_set_style_local_border_color(set_btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
    lv_obj_set_style_local_border_width(set_btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 1);
    lv_obj_set_style_local_outline_width(set_btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 0);
    lv_obj_set_size(set_btn, LV_HOR_RES / 2, LV_VER_RES / 7);
    lv_label_set_text_id(set_label, WATCH_TEXT_ID_EMODE_TEL_SET);
    lv_obj_set_event_cb(set_btn, set_btn_event_cb);
    lv_obj_align(set_btn, par, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
    lv_obj_add_style(set_label, LV_LABEL_PART_MAIN, &lv_watch_font20);
    lv_obj_add_protect(set_btn, LV_PROTECT_PRESS_LOST);
    lv_watch_obj_add_element(set_btn);
    lv_watch_obj_add_element(set_label);

    lv_obj_t * reset_btn = lv_btn_create(par, NULL);
    lv_obj_t * reset_label = lv_label_create(reset_btn, NULL);

    lv_obj_set_size(reset_btn, LV_HOR_RES / 2, LV_VER_RES / 7);
    lv_obj_set_style_local_radius(reset_btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 5);
    lv_obj_set_style_local_border_side(reset_btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_BORDER_SIDE_FULL);
    lv_obj_set_style_local_border_color(reset_btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
    lv_obj_set_style_local_border_width(reset_btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 1);
    lv_obj_set_style_local_outline_width(reset_btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 0);
    lv_label_set_text_id(reset_label, WATCH_TEXT_ID_EMODE_TEL_RESET_DEFAULT);
    lv_obj_set_event_cb(reset_btn, reset_default_btn_event_cb);
    lv_obj_align(reset_btn, set_btn, LV_ALIGN_OUT_RIGHT_MID, 0, 0);
    lv_obj_add_style(reset_label, LV_LABEL_PART_MAIN, &lv_watch_font20);
    lv_obj_add_protect(reset_btn, LV_PROTECT_PRESS_LOST);
    lv_watch_obj_add_element(reset_btn);
    lv_watch_obj_add_element(reset_label);
}

static void set_success_btn_event_cb(lv_obj_t * btn, lv_event_t e)
{
    if(LV_EVENT_CLICKED == e) {
        lv_obj_t * cont1 = lv_obj_get_parent(btn);
        lv_obj_t * cont = lv_obj_get_parent(cont1);
        lv_obj_del(cont);
    }
}

static void set_result_create(lv_obj_t * par)
{
    lv_obj_t * cont = lv_cont_create(par, NULL);
    lv_obj_set_size(cont, LV_HOR_RES, LV_VER_RES);
    lv_obj_add_style(cont, LV_CONT_PART_MAIN, &lv_watch_cont_opa2);

    lv_obj_t * cont1 = lv_cont_create(cont, NULL);
    lv_obj_set_size(cont1, LV_HOR_RES * 5 / 6, LV_VER_RES / 2);
    lv_obj_set_pos(cont1, LV_HOR_RES / 12, LV_VER_RES / 4);

    lv_obj_t * btn1 = lv_btn_create(cont1, NULL);
    lv_obj_set_size(btn1, LV_HOR_RES * 5 / 6, LV_VER_RES / 6);
    lv_engineer_main_obj_ext_t * ext = engineer_mode_get_ext();
    lv_obj_add_style(btn1, LV_BTN_PART_MAIN, &(ext->list_btn_hor_st));
    lv_obj_align(btn1, cont1, LV_ALIGN_IN_TOP_LEFT, 0, 0);
    lv_btn_set_layout(btn1, LV_LAYOUT_ROW_MID);

    lv_obj_t * label1 = lv_label_create(btn1, NULL);
    lv_obj_add_style(label1, LV_LABEL_PART_MAIN, &lv_watch_font20);
    lv_label_set_text_id(label1, WATCH_TEXT_ID_EMODE_TEL_SET_SUCCESS);

    lv_obj_t * label2 = lv_label_create(cont1, NULL);
    lv_label_set_text_id(label2, WATCH_TEXT_ID_EMODE_TEL_SET_OK);
    lv_obj_add_style(label2, LV_LABEL_PART_MAIN, &lv_watch_font20);
    lv_obj_align(label2, btn1, LV_ALIGN_OUT_BOTTOM_LEFT, 10, 15);


    lv_obj_t * btn2 = lv_btn_create(cont1, NULL);
    lv_obj_set_size(btn2, LV_HOR_RES * 5 / 6, LV_VER_RES / 6);
    lv_obj_set_style_local_border_side(btn2, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_BORDER_SIDE_FULL);
    lv_obj_set_style_local_border_color(btn2, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
    lv_obj_set_style_local_border_width(btn2, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 1);
    lv_obj_set_style_local_outline_width(btn2, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 0);
    lv_obj_set_event_cb(btn2, set_success_btn_event_cb);
    lv_obj_align(btn2, cont1, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
    lv_obj_add_protect(btn2, LV_PROTECT_PRESS_LOST);
    lv_obj_set_style_local_radius(btn2, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 5);

    lv_obj_t * label3 = lv_label_create(btn2, NULL);
    lv_label_set_text_id(label3, WATCH_TEXT_ID_OK);
    lv_obj_add_style(label3, LV_LABEL_PART_MAIN, &lv_watch_font20);
}

static void reset_cancel_btn_event_cb(lv_obj_t * btn, lv_event_t e)
{
    if(LV_EVENT_CLICKED == e) {
        lv_obj_t * cont1 = lv_obj_get_parent(btn);
        lv_obj_t * cont = lv_obj_get_parent(cont1);
        lv_obj_del(cont);
    }
}

static void reset_ok_btn_event_cb(lv_obj_t * btn, lv_event_t e)
{
    if(LV_EVENT_CLICKED == e) {
        uint8_t i = 0;
        uint8_t lte_cnt = BAND_MODE_TD_LTE_CNT + BAND_MODE_FDD_LTE_CNT;
        uint8_t lte_bitmap[2] = {};
        lv_obj_t * list = NULL;
        lv_obj_t * list_btn = NULL;
        uint32_t btn_num;
        lv_obj_t * cont1 = lv_obj_get_parent(btn);
        lv_obj_t * cont = lv_obj_get_parent(cont1);
        lv_obj_t * par = lv_obj_get_parent(cont);
        for(i = 0; i < 4; i++) {
            list = lv_obj_get_child_back(par, list);

            if(0xF0 == lv_obj_get_user_data(list).user_num) {
                break;
            }
        }

        // reset to default setting
        lv_band_mode_obj_ext_t * band_mode_ext = band_mode_get_ext();
        memset(band_mode_ext->gsm_band_sel, 1, BAND_MODE_GSM_CNT);
        memset(band_mode_ext->fdd_lte_band_sel, 1, BAND_MODE_FDD_LTE_CNT);
        memset(band_mode_ext->td_lte_band_sel, 1, BAND_MODE_TD_LTE_CNT);

        band_mode_ext->gsm_bitmap = ENGINEER_MODE_DEF_GSM_BAND;
        band_mode_ext->lte_bitmap = ENGINEER_MODE_DEF_LTE_BAND;

        lte_bitmap[0] = (uint8_t)band_mode_ext->lte_bitmap;
        lte_bitmap[1] = (uint8_t)(band_mode_ext->lte_bitmap >> 8);

        // update NV
        UI_NV_Write_Req(NV_SECTION_UI_ENGINEER_MODE, 1, 1, &band_mode_ext->gsm_bitmap);
        UI_NV_Write_Req(NV_SECTION_UI_ENGINEER_MODE, 2, 2, lte_bitmap);

        config_modem_sel_band();

        // update band_mode test UI
        if(NULL != list) {
            lv_obj_t * scrl = lv_page_get_scrl(list);

            for(i = 0; i < BAND_MODE_GSM_CNT + lte_cnt + 2; i++) {
                list_btn = lv_obj_get_child_back(scrl, list_btn);
                btn_num = lv_obj_get_user_data(list_btn).user_num;
                if(0xFF == btn_num) {
                    continue;
                } else {
                    update_sel_band(list_btn, btn_num);
                }
            }
        }

        lv_obj_del(cont);
    }
}

static void reset_result_create(lv_obj_t * par)
{
    lv_obj_t * cont = lv_cont_create(par, NULL);
    lv_obj_set_size(cont, LV_HOR_RES, LV_VER_RES);
    lv_obj_add_style(cont, LV_CONT_PART_MAIN, &lv_watch_cont_opa2);

    lv_obj_t * cont1 = lv_cont_create(cont, NULL);
    lv_obj_set_size(cont1, LV_HOR_RES * 5 / 6, LV_VER_RES / 2);
    lv_obj_set_pos(cont1, LV_HOR_RES / 12, LV_VER_RES / 4);

    lv_obj_t * btn1 = lv_btn_create(cont1, NULL);
    lv_obj_set_size(btn1, LV_HOR_RES * 5 / 6, LV_VER_RES / 6);
    lv_engineer_main_obj_ext_t * ext = engineer_mode_get_ext();
    lv_obj_add_style(btn1, LV_BTN_PART_MAIN, &(ext->list_btn_hor_st));
    lv_obj_align(btn1, cont1, LV_ALIGN_IN_TOP_LEFT, 0, 0);
    lv_btn_set_layout(btn1, LV_LAYOUT_ROW_MID);

    lv_obj_t * label1 = lv_label_create(btn1, NULL);
    lv_obj_add_style(label1, LV_LABEL_PART_MAIN, &lv_watch_font20);
    lv_label_set_text_id(label1, WATCH_TEXT_ID_EMODE_TEL_RESET);

    lv_obj_t * label2 = lv_label_create(cont1, NULL);
    lv_label_set_text_id(label2, WATCH_TEXT_ID_EMODE_TEL_RESET_DEFAULT_Q);
    lv_obj_add_style(label2, LV_LABEL_PART_MAIN, &lv_watch_font20);
    lv_obj_align(label2, btn1, LV_ALIGN_OUT_BOTTOM_LEFT, 10, 15);


    lv_obj_t * btn2 = lv_btn_create(cont1, NULL);
    lv_obj_set_size(btn2, LV_HOR_RES * 5 / 12, LV_VER_RES / 6);
    lv_obj_set_event_cb(btn2, reset_cancel_btn_event_cb);
    lv_obj_align(btn2, cont1, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
    lv_obj_add_protect(btn2, LV_PROTECT_PRESS_LOST);
    lv_obj_set_style_local_radius(btn2, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 5);
    lv_obj_set_style_local_border_side(btn2, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_BORDER_SIDE_FULL);
    lv_obj_set_style_local_border_color(btn2, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
    lv_obj_set_style_local_border_width(btn2, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 1);
    lv_obj_set_style_local_outline_width(btn2, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 0);

    lv_obj_t * label3 = lv_label_create(btn2, NULL);
    lv_label_set_text_id(label3, WATCH_TEXT_ID_CANCEL);
    lv_obj_add_style(label3, LV_LABEL_PART_MAIN, &lv_watch_font20);

    lv_obj_t * btn3 = lv_btn_create(cont1, NULL);
    lv_obj_set_size(btn3, LV_HOR_RES * 5 / 12, LV_VER_RES / 6);
    lv_obj_set_event_cb(btn3, reset_ok_btn_event_cb);
    lv_obj_align(btn3, btn2, LV_ALIGN_OUT_RIGHT_MID, 0, 0);
    lv_obj_add_protect(btn3, LV_PROTECT_PRESS_LOST);
    lv_obj_set_style_local_radius(btn3, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 5);
    lv_obj_set_style_local_border_side(btn3, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_BORDER_SIDE_FULL);
    lv_obj_set_style_local_border_color(btn3, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
    lv_obj_set_style_local_border_width(btn3, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 1);
    lv_obj_set_style_local_outline_width(btn3, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 0);

    lv_obj_t * label4 = lv_label_create(btn3, NULL);
    lv_label_set_text_id(label4, WATCH_TEXT_ID_OK);
    lv_obj_add_style(label4, LV_LABEL_PART_MAIN, &lv_watch_font20);

}

static void set_btn_event_cb(lv_obj_t * btn, lv_event_t e)
{
    if(LV_EVENT_CLICKED == e) {
        uint8_t lte_bitmap[2] = {};
        lv_band_mode_obj_ext_t * band_mode_ext = band_mode_get_ext();
        band_mode_ext->gsm_bitmap = update_gsm_band_bitmap();
        band_mode_ext->lte_bitmap = update_lte_band_bitmap();

        // if user select nothing, set bitmap to default
        if((0 == band_mode_ext->gsm_bitmap) && (0 == band_mode_ext->lte_bitmap)) {
            memset(band_mode_ext->gsm_band_sel, 1, BAND_MODE_GSM_CNT);
            memset(band_mode_ext->fdd_lte_band_sel, 1, BAND_MODE_FDD_LTE_CNT);
            memset(band_mode_ext->td_lte_band_sel, 1, BAND_MODE_TD_LTE_CNT);

            band_mode_ext->gsm_bitmap = ENGINEER_MODE_DEF_GSM_BAND;
            band_mode_ext->lte_bitmap = ENGINEER_MODE_DEF_LTE_BAND;

            // update band_mode test UI
            uint8_t i = 0;
            lv_obj_t * list = NULL;
            lv_obj_t * list_btn = NULL;
            uint32_t btn_num;
            uint8_t lte_cnt = BAND_MODE_FDD_LTE_CNT + BAND_MODE_TD_LTE_CNT;
            lv_obj_t * par = lv_obj_get_parent(btn);

            for(i = 0; i < 4; i++) {
                list = lv_obj_get_child_back(par, list);

                if(0xF0 == lv_obj_get_user_data(list).user_num) {
                    break;
                }
            }

            if(NULL != list) {
                lv_obj_t * scrl = lv_page_get_scrl(list);

                for(i = 0; i < BAND_MODE_GSM_CNT + lte_cnt + 2; i++) {
                    list_btn = lv_obj_get_child_back(scrl, list_btn);
                    btn_num = lv_obj_get_user_data(list_btn).user_num;
                    if(0xFF == btn_num) {
                        continue;
                    } else {
                        update_sel_band(list_btn, btn_num);
                    }
                }
            }
        }

        lte_bitmap[0] = (uint8_t)band_mode_ext->lte_bitmap;
        lte_bitmap[1] = (uint8_t)(band_mode_ext->lte_bitmap >> 8);

        // update NV
        UI_NV_Write_Req(NV_SECTION_UI_ENGINEER_MODE, 1, 1, &band_mode_ext->gsm_bitmap);
        UI_NV_Write_Req(NV_SECTION_UI_ENGINEER_MODE, 2, 2, lte_bitmap);

        config_modem_sel_band();

        lv_obj_t * par = lv_obj_get_parent(btn);
        set_result_create(par);
    }
}

static void reset_default_btn_event_cb(lv_obj_t * btn, lv_event_t e)
{
    if(LV_EVENT_CLICKED == e) {
        lv_obj_t * par = lv_obj_get_parent(btn);
        reset_result_create(par);
    }
}

static void config_modem_sel_band(void)
{
    uint32_t i = 1;
    uint8_t band_mode = ENGINEER_MODE_GSM_MODE;
    uint16_t lte_band_h = 0;
    uint32_t lte_band_l = 0;

    lv_band_mode_obj_ext_t * band_mode_ext = band_mode_get_ext();

    // get band38 ~ band41
    lte_band_h = 0x1E00 & band_mode_ext->lte_bitmap;
    lte_band_h >>= 4;

    // get band0 ~ band5
    lte_band_l = (uint32_t)(0x001F & band_mode_ext->lte_bitmap);
    // get band7
    if(0x0020 & band_mode_ext->lte_bitmap) {
        lte_band_l |= (uint32_t)(i << 6);
    }
    // get band13
    if(0x0040 & band_mode_ext->lte_bitmap) {
        lte_band_l |= (uint32_t)(i << 12);
    }
    // get band17
    if(0x0080 & band_mode_ext->lte_bitmap) {
        lte_band_l |= (uint32_t)(i << 16);
    }
    // get band20
    if(0x0100 & band_mode_ext->lte_bitmap) {
        lte_band_l |= (uint32_t)(i << 19);
    }

    if((0 != lte_band_h) || (0 != lte_band_l)) {
        band_mode = ENGINEER_MODE_LTE_MODE;

        if(0 != band_mode_ext->gsm_bitmap) {
            band_mode = ENGINEER_MODE_DUAL_MODE_GSM_LTE_AUTO;
        }
    }

    printf("bandmode:%d, gsmband: 0x%x, ltebandh: 0x%x, ltebandl: 0x%x\n", band_mode, band_mode_ext->gsm_bitmap, lte_band_h, lte_band_l);

    watch_modem_set_band_req(band_mode, band_mode_ext->gsm_bitmap, lte_band_h, lte_band_l);
}

/**
 * process the calibration result
 * param (in) result: uint8_t
 * return  void
 */
void watch_modem_calibration_result_process(uint8_t result)
{
    lv_engineer_main_obj_ext_t * ext = engineer_mode_get_ext();
    lv_obj_t * label_rslt = ext->label_rslt;
    lv_obj_t * par = lv_obj_get_parent(label_rslt);

    printf("%s: result = %d\n", __FUNCTION__, result);

    if(1 == result) {
        lv_label_set_text_id(label_rslt, WATCH_TEXT_ID_EMODE_TEL_CALIBRATION_PASS);
    } else {
        lv_label_set_text_id(label_rslt, WATCH_TEXT_ID_EMODE_TEL_CALIBRATION_FAIL);
    }
    lv_obj_align(label_rslt, par, LV_ALIGN_IN_TOP_MID, 0, LV_VER_RES * 2 / 5);
}

/**
 * process the lte cells information
 * param (in) psn: int8_t*
 * return  void
 */
void watch_modem_sn_info_process(char * psn)
{
    lv_engineer_main_obj_ext_t * ext = engineer_mode_get_ext();
    lv_obj_t * label_rslt = ext->label_rslt;
    lv_obj_t * par = lv_obj_get_parent(label_rslt);

    printf("%s:psn = %s\n", __FUNCTION__, psn);

    if(NULL == psn) {
        lv_label_set_text_id(label_rslt, WATCH_TEXT_ID_EMODE_TEL_SN_FAIL);
    } else {
        lv_label_set_text(label_rslt, psn);
        lv_mem_free(psn);
    }

    lv_obj_align(label_rslt, par, LV_ALIGN_IN_TOP_MID, 0, LV_VER_RES * 2 / 5);
}

#endif /*USE_LV_WATCH_ENGINEER_MODE*/
